#include <linux/module.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/init.h>
#include <linux/device.h>

#include "led_opr.h"
#include "led_resource.h"

static struct led_resource *led_res; 

static int board_demo_led_init(int which)
{
    if(!led_res){
        led_res = get_led_resource();
    }
    
    printk("init gpio: group %d, pin %d\n",GROUP(led_res->pin),PIN(led_res->pin));
    switch(GROUP(led_res->pin))
    {
        case 0:
        {
            printk("init pin of group 0 ...\n");
            break;
        }
        case 1: 
        {
            printk("init pin of group 1 ...\n");
            break;
        }
        case 2:
        {
            printk("init pin of group 2 ...\n");
            break;
        }
        case 3:
        {
            printk("init pin of group 3 ...\n");
            break;
        } 
    }
	return 0;
}

/* LED control 
 * which : which LED 
 * status : 1-亮， 0-灭
 */
static int board_demo_led_ctl(int which,char status)
{
    printk("set led %s: group %d, pin %d \n",status ? "on" : "off",  GROUP(led_res->pin), PIN(led_res->pin));
    
    switch(GROUP(led_res->pin))
    {
        case 0:
        {
            printk("set pin of group 0 ...\n");
            break;
        }
        case 1:
        {
            printk("set pin of group 1 ...\n");
            break;
        }
        case 2:
        {
            printk("set pin of group 2 ...\n");
            break;
        }
        case 3:
        {
            printk("set pin of group 3 ...\n");
            break;
        }
    }
	return 0;
}

static struct  led_operations board_demo_led_opr = {
	.init = board_demo_led_init,
	.ctl  = board_demo_led_ctl,
};

struct led_operations *get_board_led_opr(void)
{
	return &board_demo_led_opr;
}
